#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <logindialog.h>
#include <adduserdialog.h>
#include <usersql.h>

#include <QListWidgetItem>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QDebug>
#include <QLabel>
#include <QMoveEvent>
#include <QDir>
#include <QStandardItem>
#include <QStringList>
#include <QListWidgetItem>
#include <QPushButton>
#include <QMouseEvent>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QSqlQueryModel>
#include <QCoreApplication>
#include <QList>


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    static MainWindow *ptrstuSql;
    static MainWindow *getinstance()
    {
        if(ptrstuSql == nullptr)
        {
            ptrstuSql = new MainWindow;
        }
        return ptrstuSql;
    }

    explicit MainWindow(QWidget *parent = 0);
    //查询总人数
    int getUserCnt();
    //查询搜索的人
    int getUserCntByName(QString name);
    //查询用户信息
    User getUserById(int id);
    //查询第几页的数据
    QList<User> getPageUser(int page, int cnt);
    //增加用户
    bool addUser(User user);
    //删除用户
    bool delUser(int id);
    //更新用户信息
    bool updateUser(User user);
    //查询用户的详细信息
    QList<Info> getAllInfoById(int id);
    //查询用户首次信息
    Info getFirstInfoById(int id);
    //查询用户非首次的单条信息
    Info getInfoById(int id);
    //查询是否存在该用户的信息
    bool isExistFirstInfo(QString id);
    //删除用户非首次的单条信息
    bool delInfoById(QString id);
    //添加用户首次信息
    bool addFirstInfoById(QString id, QString time, QString symptom, QString age, QString passtime, QString height, QString weight, QString smoke, QString pill, QString cill, QString till, QString mill, QString antibody_path, QString blood_path, QString technical_path, QString scale, QString scale_path, QString diagnosis, QString diagnosis_path, QString method, QString MGFA);
    //添加用户非首次信息
    bool addInfoById(QString id, QString time, QString symptom, QString height, QString weight, QString cill, QString till, QString mill, QString antibody_path, QString blood_path, QString technical_path, QString scale, QString scale_path, QString diagnosis, QString diagnosis_path, QString method, QString MGFA);
    //更新用户首次信息
    bool updateFirstInfoById(QString id, QString time, QString symptom, QString age, QString passtime, QString height, QString weight, QString smoke, QString pill, QString cill, QString till, QString mill, QString antibody_path, QString blood_path, QString technical_path, QString scale, QString scale_path, QString diagnosis, QString diagnosis_path, QString method, QString MGFA);
    //更新用户非首次信息
    bool updateInfoById(QString id, QString time, QString symptom, QString height, QString weight, QString cill, QString till, QString mill, QString antibody_path, QString blood_path, QString technical_path, QString scale, QString scale_path, QString diagnosis, QString diagnosis_path, QString method, QString MGFA);
    ~MainWindow();

private slots:
    void listWidgetClicked(QListWidgetItem*);

    void on_btn_add_clicked();
    
    void on_btn_search_clicked();

    void on_btn_homepage_clicked();

    void on_btn_uppage_clicked();

    void on_btn_nextpage_clicked();

    void on_btn_lastpage_clicked();

private:
    void updateMainWindowBySearch();

public:
    void updateMainWindow();
    userSql us;

private:
    Ui::MainWindow *ui;
    QSqlDatabase db;
    addUserDialog add_User;
};

#endif // MAINWINDOW_H
